package com.airline.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.airline.beans.Employee;
import com.airline.beans.Flight;
import com.airline.connection.AirlineSystemServiceProxy;
import com.airline.form.UpdateFlightForm;
import com.airline.form.UpdateFlightIDForm;

public class FlightIDAction extends DispatchAction{
	
	AirlineSystemServiceProxy proxy = new AirlineSystemServiceProxy();
	public ActionForward updateId(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		UpdateFlightForm flightform = new UpdateFlightForm();
		String flightid = request.getParameter("empid");
		
		Flight flight = proxy.getFlight(flightid);

		if (null == flight) {

		((UpdateFlightIDForm)	(form)).setError("No Flight with the ID " + flightid + " exists");
			return mapping.findForward("failure");
		}
		
		

		flightform.setFlight(flight);
		
		
		request.getSession().setAttribute("updateFlightForm", flightform);
		return mapping.findForward("update");
		
	}
		
	
	

}
